package com.yycx.module.bus.provider.handler.haiying.order;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.GetInterceptor;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.security.OpenHelper;
import com.yycx.module.bus.client.entity.BusCustom;
import com.yycx.module.bus.client.entity.hy.HyOrder;
import com.yycx.module.bus.provider.service.BusCustomService;
import com.yycx.module.bus.provider.service.hy.HyOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 海鹰订单核算tab详情查询
 *
 * @author zyf
 */
@Component("hyCalCulateTab1GetHandler")
public class HyCalCulateTab1GetHandler implements GetInterceptor {


    @Autowired
    private HyOrderService orderService;
    @Autowired
    private BusCustomService customService;

    @Override
    public ResultBody validate(CriteriaQuery cq, EntityMap params) {
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaQuery cq, EntityMap entityMap) {

    }

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        Long customId = map.getLong("customId");
        Integer customPolicy = map.getInt("customPolicy", 0);
        String orderId = map.get("orderId");
        HyOrder order = orderService.getById(orderId);
        map.put("sendType", order.getSendType());
        map.put("customBondType", order.getCustomBondType());
        BusCustom busCustom = customService.getById(customId);
        if (FlymeUtils.isNotEmpty(busCustom)) {
            Boolean settleType = busCustom.getSettleType();
            if (settleType) {
                map.put("settleType", 1);
            } else {
                map.put("settleType", 0);
            }
        }
        Boolean disabled = customPolicy.equals(0);
        if (order.getCalculateState().equals(2)) {
            disabled = true;
        }
        map.put("disabled", disabled);
    }

}
